package com.example.guoxun.livewallpagerdemo;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class WelcomeActivity extends AppCompatActivity implements View.OnClickListener {

    ImageView mHandImageView;
    TextView mRefuseTextView;
    Button mDownloadButton;

    TranslateAnimation mHandTranslateAnimation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);

        initView();
        initAnimation();
    }

    private void initView() {
        mHandImageView = (ImageView) findViewById(R.id.image_view_hand);
        mRefuseTextView = (TextView) findViewById(R.id.refuse_download_btn);
        mDownloadButton = (Button) findViewById(R.id.download_btn);

        mRefuseTextView.setOnClickListener(this);
        mDownloadButton.setOnClickListener(this);
    }

    private void initAnimation() {
        mHandTranslateAnimation = new TranslateAnimation(0, 50, -100, 100);
        mHandTranslateAnimation.setDuration(1200);
        mHandTranslateAnimation.setRepeatCount(Animation.INFINITE);
        mHandTranslateAnimation.setRepeatMode(Animation.REVERSE);
        mHandImageView.setAnimation(mHandTranslateAnimation);
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mHandImageView.startAnimation(mHandTranslateAnimation);
    }

    @Override
    protected void onPause() {
        super.onPause();
        mHandImageView.clearAnimation();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.refuse_download_btn: {
                Intent intent = new Intent(this, MainActivity.class);
                startActivity(intent);
                finish();
                break;
            }
            case R.id.download_btn: {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                /**
                 * Uri.parse("market://search?q=pub:Author Name"); //跳转到商店搜索界面，并搜索开发者姓名
                 * Uri.parse("market://search?q=Keyword"); //跳转到商店搜索界面，并搜索关键词
                 */
                intent.setData(Uri.parse("market://details?id=com.netease.cloudmusic"));
                startActivity(intent);
                break;
            }
        }
    }
}